<template>
  <div>
    <!--  填写国内运单号弹窗  -->
    <el-dialog
      title="填写国内运单信息"
      :visible.sync="isOpen"
      width="500px"
      :before-close="close">
      <div v-if="sendGoodsInfoList && sendGoodsInfoList.length>0">
        <div v-for="(item,index) in sendGoodsInfoList" :key="index">
          <!--          <span class="programme-box-item-title">子订单号：{{ item.childOrderId }}</span>-->
          <el-form size="small" :model="item" :rules="rules" ref="formRef"
                   label-width="120px">
            <el-form-item label="子订单号：" prop="childOrderId">
              <el-input disabled v-model="item.childOrderId" placeholder="请输入运单号"/>
            </el-form-item>
            <el-form-item label="运单号：" prop="trackingNo"
                          :rules="[{ required: false, message: '申报中文名称不能为空', trigger: 'blur' },]">
              <el-input v-model="item.trackingNo" placeholder="请输入运单号"/>
            </el-form-item>
            <el-form-item label="预计到货日期：" prop="arrivalTime">
              <el-date-picker
                v-model="item.arrivalTime"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="选择预计到货日期">
              </el-date-picker>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <!--      <div v-else>-->
      <!--        <el-form size="small" :model="form" :rules="rules" ref="formRef"-->
      <!--                 label-width="120px">-->
      <!--          <el-form-item label="运单号：" prop="trackingNo"-->
      <!--                        :rules="[{ required: false, message: '申报中文名称不能为空', trigger: 'blur' },]">-->
      <!--            <el-input v-model="form.trackingNo" placeholder="请输入运单号"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="预计到货日期：" prop="arrivalTime">-->
      <!--            <el-date-picker-->
      <!--              v-model="form.arrivalTime"-->
      <!--              type="date"-->
      <!--              format="yyyy-MM-dd"-->
      <!--              value-format="yyyy-MM-dd"-->
      <!--              placeholder="选择预计到货日期">-->
      <!--            </el-date-picker>-->
      <!--          </el-form-item>-->
      <!--        </el-form>-->
      <!--      </div>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="confirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  cutOrderStorage,
} from "@/api/order/purchaser"
import {formatDate} from "@/utils";

export default {
  name: 'order-list',
  props: {
    sendGoodsInfoList: {
      type: Array
    },
    isOpenTransferWarehouse: {
      type: Boolean,
    },
    orderId: {
      type: String / Number
    },
    childOrderId: {
      type: String / Number
    }
  },
  data() {
    return {
      isOpen: true,
      form: {},//国内运单号信息
      rules: { // 线上发货表单校验
        trackingNo: [{required: false, message: '国内运单号不能为空', trigger: 'blur'}],
        arrivalTime: [{required: false, message: '预计到达时间不能为空', trigger: 'blur'}],
      },
      sendGoodsList: this.sendGoodsInfoList
    }
  },
  mounted() {
    this.getSendGoodsInfo()
  },
  methods: {
    // 获取已上传的凭证和运单号信息
    getSendGoodsInfo() {

    },
    // 确定国内运单号
    confirm() {
      // this.$refs['formRef'].validate((valid) => {
      //   if (valid) {
      // let time = new Date(this.arrivalTime + " " + '23:59:59')
      // this.domesticWaybillInfo.orderId = this.orderId
      // this.domesticWaybillInfo.childOrderId = this.childOrderId
      // this.domesticWaybillInfo.arrivalTime = time.getTime()
      if (this.sendGoodsInfoList && this.sendGoodsInfoList.length > 0) {
        for (let i = 0; i < this.sendGoodsList.length; i++) {
          let time = new Date(this.sendGoodsList[i].arrivalTime)
          console.log('time', time)
          this.sendGoodsList[i].arrivalTime = time.getTime()
        }
      } else {
        this.form.childOrderId = this.childOrderId
        this.form.orderId = this.orderId
        this.sendGoodsList.push(this.form)
      }


      // let data = {
      //   // orderParamList: JSON.stringify(this.sendGoodsList)
      //   orderParamList: this.sendGoodsList
      // }
      cutOrderStorage(this.sendGoodsList).then(res => {
        this.$message.success(res.msg)
        this.close()
      })
      //   }
      // })
    },
    // 关闭线上发货弹窗
    close() {
      this.$emit('closeTransferWarehouse', false)
    },
  }
}
</script>
<style scoped>
.el-divider__text {
  font-size: 16px;
  font-weight: bold;
  color: #000;
}
</style>
